import com.qian.api.ddj.util.SignUtils;
import com.yaowk.api.utils.HttpUtils;
import org.apache.commons.codec.digest.DigestUtils;
import org.junit.Test;

import java.util.LinkedHashMap;
import java.util.Map;

public class SYK {

    @Test
    public void pay() {
        Map<String, String> map = new LinkedHashMap<>();

        map.put("p0_Cmd", "PreCreate");
        map.put("p1_Account", "18695678278");
        map.put("p2_Amt", "2");
        map.put("p3_ProductCode", "QR_CODE_OFFLINE");
        map.put("p7_plat", "1");
        map.put("p8_Channel", "1");
        map.put("p9_Notify_Url", "http://www.baidu.com");

        String sign = SignUtils.params(map);
        sign = DigestUtils.md5Hex(sign + "&key=D81243076DDAD150A1034725E56511F8");

        map.put("hmac", sign);

        String body = SignUtils.params(map);
        String rec = HttpUtils.post("http://a.xfpay.cn/api/ApiHandler.ashx", body);
        System.out.println(rec);
    }

    @Test
    public void query() {
        Map<String, String> map = new LinkedHashMap<>();

        map.put("p0_Cmd", "QueryTrade");
        map.put("p1_Account", "18695678278");
        map.put("p2_out_trade_no", "1");
        map.put("p4_plat", "5");

        String sign = SignUtils.params(map);
        sign = DigestUtils.md5Hex(sign + "&key=6053B91D59A173C4D3E636ED105AF097");

        map.put("hmac", sign);

        String body = SignUtils.params(map);
        String rec = HttpUtils.post("http://a.xfpay.cn/api/ApiHandler.ashx", body);
        System.out.println(rec);
    }
}
